package com.norbitltd.guavaleaves.java.lang;

import org.apache.commons.lang3.BooleanUtils;

import com.google.common.base.Function;

public class BooleanFunctions extends ObjectFunctions {
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toStringOnOff
	 */
	public static Function<Boolean, String> toStringOnOff() {
		return new Function<Boolean, String>() {
			public String apply(Boolean input) {
				return BooleanUtils.toStringOnOff(input);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toStringTrueFalse
	 */
	public static Function<Boolean, String> toStringTrueFalse() {
		return new Function<Boolean, String>() {
			public String apply(Boolean input) {
				return BooleanUtils.toStringTrueFalse(input);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toStringYesNo
	 */
	public static Function<Boolean, String> toStringYesNo() {
		return new Function<Boolean, String>() {
			public String apply(Boolean input) {
				return BooleanUtils.toStringYesNo(input);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toString
	 */
	public static Function<Boolean, String> toString(final String trueString, final String falseString,  final String nullString) {
		return new Function<Boolean, String>() {
			public String apply(Boolean input) {
				return BooleanUtils.toString(input, trueString, falseString, nullString);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toIntegerObject
	 */
	public static Function<Boolean, Integer> toIntegerObject() {
		return new Function<Boolean, Integer>() {
			public Integer apply(Boolean input) {
				return BooleanUtils.toIntegerObject(input);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.toString
	 */
	public static Function<Boolean, Integer> toIntegerObject(final Integer trueValue, final Integer falseValue,  final Integer nullValue) {
		return new Function<Boolean, Integer>() {
			public Integer apply(Boolean input) {
				return BooleanUtils.toIntegerObject(input, trueValue, falseValue, nullValue);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.BooleanUtils.negate
	 */
	public static Function<Boolean, Boolean> negate() {
		return new Function<Boolean, Boolean>() {
			public Boolean apply(Boolean input) {
				return BooleanUtils.negate(input);
			}
		};
	}
	
	public static Function<Boolean, Boolean> and(final Boolean b) {
		return new Function<Boolean, Boolean>() {
			public Boolean apply(Boolean input) {
				if( input == null) {
					return null;
				} else {
					return input && b;
				}
			}
		};
	}
	
	public static Function<Boolean, Boolean> or(final Boolean b) {
		return new Function<Boolean, Boolean>() {
			public Boolean apply(Boolean input) {
				if( input == null) {
					return null;
				} else {
					return input || b;
				}
			}
		};
	}
	
	public static Function<Boolean, Boolean> xor(final Boolean b) {
		return new Function<Boolean, Boolean>() {
			public Boolean apply(Boolean input) {
				if( input == null) {
					return null;
				} else {
					return input ^ b;
				}
			}
		};
	}
}
